/*
 * Copyright (C) 2017 Spreadtrum Communications Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include "sprd_panel.h"
#include "sprd_dsi.h"
#include "dsi/mipi_dsi_api.h"
#include "sprd_dphy.h"
#include <i2c.h>

#define I2C_SPEED	100000
#define BL_POWER_I2C_ADDRESS          0x36
#define BL_POWER_MODE_ADDRESS         0x02
#define BL_CURRENT_RATIO_LSB_ADDRESS         0x04
#define BL_CURRENT_RATIO_MSB_ADDRESS          0x05
#define BL_POWER_PWM_ADDRESS         		 0x06
#define BL_POWER_TURNON_RAMP_ADDRESS          0x07

#define LCD_POWER_I2C_ADDRESS          0x3E
#define LCD_POWER_VPOS_ADDRESS         0x00
#define LCD_POWER_VNEG_ADDRESS         0x01
#define LCD_POWER_DIS_ADDRESS          0x03
#define LCD_POWER_CTL_ADDRESS          0xFF

static uint8_t init_data[] = {
	//-------------  Display Initial Code Setting  -------------------------
	//Stop reload
	0x39, 0x00, 0x00, 0x02, 0x41,0x5A,

	//INT CANCEL
	0x39, 0x00, 0x00, 0x02, 0x4C,0x03,

	//VCOM
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x03,
	0x39, 0x00, 0x00, 0x03, 0x80,0xA9,0x00,

	//----------------------LCD initial code start----------------------//
	//Blank 9
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x09,
	0x39, 0x00, 0x00, 0x06, 0x80,0x64,0x00,0x64,0x00,0x00,
	//Blank 10
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x0A,
	0x39, 0x00, 0x00, 0x11, 0x80,0xA5,0x15,0xA5,0xAA,0xA5,0x88,0x42,0xC8,0x8C,0x03,0x07,0x05,0x39,0x61,0x32,0x5A,
	0x39, 0x00, 0x00, 0x11, 0x90,0x0C,0x0F,0x22,0x00,0x2A,0x18,0x64,0x00,0x88,0x03,0x03,0xEE,0xEE,0x00,0x3F,0x2A,
	0x39, 0x00, 0x00, 0x11, 0xA0,0x00,0x30,0x02,0x32,0x11,0x0D,0x60,0x01,0xFF,0xFF,0x03,0x40,0x42,0x0F,0x94,0x11,
	0x39, 0x00, 0x00, 0x11, 0xB0,0xE8,0x03,0x00,0x00,0x11,0x0D,0x60,0x00,0xFF,0xFF,0x03,0xFF,0x34,0x0C,0x0F,0x0E,
	0x39, 0x00, 0x00, 0x0B, 0xC0,0x1F,0x03,0x00,0x08,0x20,0x34,0x00,0x00,0x00,0x00,
	//Blank 11
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x0B,
	0x39, 0x00, 0x00, 0x11, 0x80,0xFF,0xBE,0xE6,0x00,0x00,0x04,0x10,0x1D,0x26,0x30,0x40,0x4D,0x51,0x5E,0x63,0x7A,
	0x39, 0x00, 0x00, 0x11, 0x90,0x86,0x70,0x6F,0x62,0x5A,0x4C,0x3D,0x33,0x29,0x18,0x06,0x01,0x00,0x04,0x10,0x1D,
	0x39, 0x00, 0x00, 0x11, 0xA0,0x26,0x30,0x40,0x4D,0x51,0x5E,0x63,0x7A,0x86,0x70,0x6F,0x62,0x5A,0x4C,0x3D,0x33,
	0x39, 0x00, 0x00, 0x06, 0xB0,0x29,0x18,0x06,0x01,0x00,
	//Blank 12
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x0C,
	0x39, 0x00, 0x00, 0x11, 0x80,0x00,0x00,0x20,0x42,0x00,0x00,0x80,0x05,0x54,0x00,0x00,0x00,0x20,0x42,0x00,0x00,
	0x39, 0x00, 0x00, 0x03, 0x90,0x80,0x05,
	//Blank 13
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x0D,
	0x39, 0x00, 0x00, 0x11, 0x80,0x7A,0xD0,0x02,0x40,0x06,0xD7,0x00,0xFA,0x00,0x0A,0x0A,0x0A,0x0A,0x00,0x01,0x03,
	0x39, 0x00, 0x00, 0x11, 0x90,0x00,0x00,0x00,0x00,0xAC,0xA2,0x2A,0x00,0x00,0x00,0xAC,0xA2,0x2A,0x57,0x31,0x00,
	0x39, 0x00, 0x00, 0x11, 0xA0,0x00,0x00,0x00,0x00,0x00,0xAC,0xA2,0x2A,0xAA,0xC2,0x2A,0xAC,0xA2,0x2A,0xAA,0xC2,
	0x39, 0x00, 0x00, 0x07, 0xB0,0x2A,0x00,0x00,0x00,0xAA,0x52,
	//Blank 14
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x0E,
	0x39, 0x00, 0x00, 0x0d, 0x80,0xF0,0xB1,0x71,0xEF,0x4B,0x20,0x37,0x0F,0xAA,0xAA,0x00,0x00,
	//Blank 15
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x0F,
	0x39, 0x00, 0x00, 0x0c, 0x80,0xFF,0x00,0x55,0x55,0x23,0x88,0x88,0x1C,0x00,0x5A,0x5A,
	//Blank 16
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x10,
	0x39, 0x00, 0x00, 0x11, 0x80,0xB5,0x45,0x09,0x18,0x01,0x3C,0x94,0x32,0x10,0xC4,0xC4,0x04,0x00,0x60,0xC0,0x00,
	0x39, 0x00, 0x00, 0x11, 0x90,0x04,0x00,0x00,0x86,0x10,0x31,0x98,0x34,0x34,0x34,0x26,0x26,0x3E,0x1A,0x62,0x20,
	0x39, 0x00, 0x00, 0x05, 0xA0,0x0C,0x40,0x00,0x8A,
	//Blank 17
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x11,
	0x39, 0x00, 0x00, 0x11, 0x80,0x00,0x00,0x03,0xE7,0x1F,0x17,0x10,0x48,0x80,0xAA,0x90,0x1A,0x30,0x88,0x41,0x8A,
	0x39, 0x00, 0x00, 0x10, 0x90,0x39,0x28,0xA9,0xC5,0x9A,0x7B,0xF0,0x07,0x7E,0xE0,0x07,0x7E,0x20,0x10,0x00,
	//Blank 18
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x12,
	0x39, 0x00, 0x00, 0x11, 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x41,0x37,
	0x39, 0x00, 0x00, 0x11, 0x90,0x2D,0x23,0x19,0x0F,0x05,0xFB,0xF1,0xE7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x39, 0x00, 0x00, 0x11, 0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x39, 0x00, 0x00, 0x11, 0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2D,0x23,0x05,0xFB,0x00,0x2D,0x23,
	0x39, 0x00, 0x00, 0x05, 0xC0,0x05,0xFB,0x00,0x01,
	//Blank 19
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x13,
	0x39, 0x00, 0x00, 0x11, 0x80,0xFD,0x0F,0x00,0x0C,0x00,0x80,0x80,0x87,0x00,0x07,0x22,0x06,0xE7,0xB9,0x86,0x1A,
	0x39, 0x00, 0x00, 0x11, 0x90,0x32,0x00,0xA2,0x2D,0x65,0x00,0x00,0x00,0x00,0xD0,0xC9,0xB7,0xFE,0x26,0x6F,0x32,
	0x39, 0x00, 0x00, 0x04, 0xA0,0x22,0x90,0x04,
	//Blank 20
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x14,
	0x39, 0x00, 0x00, 0x11, 0x80,0x01,0x02,0x40,0x5E,0xD1,0xDF,0xEF,0xF7,0xFB,0xFD,0x02,0x00,0x00,0x20,0x8B,0x0F,
	0x39, 0x00, 0x00, 0x11, 0x90,0xD1,0x7B,0x40,0x6C,0x88,0xDE,0x03,0xE2,0x42,0xF4,0x1E,0x10,0x13,0xA2,0xF7,0x00,
	0x39, 0x00, 0x00, 0x11, 0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x02,0x00,0x00,0x00,0x00,0x00,
	0x39, 0x00, 0x00, 0x11, 0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x64,0x43,0x56,0x00,0x80,0x42,
	0x39, 0x00, 0x00, 0x11, 0xC0,0xA1,0xF0,0x0E,0x44,0xEF,0x01,0xA5,0x38,0xDE,0x80,0xE8,0x3D,0xA0,0x14,0xC7,0x0B,
	0x39, 0x00, 0x00, 0x11, 0xD0,0x10,0xBD,0x07,0x94,0xE2,0x78,0x05,0xA2,0xF7,0x80,0x52,0x1C,0xEF,0x42,0xF4,0x1E,
	0x39, 0x00, 0x00, 0x11, 0xE0,0x50,0x8A,0xE3,0x4D,0x88,0xDE,0x03,0x4A,0x71,0xBC,0x07,0xD1,0x7B,0x40,0x29,0x8E,
	0x39, 0x00, 0x00, 0x11, 0xF0,0xB7,0x20,0x7A,0x0F,0x28,0xC5,0x31,0x02,0x7E,0xBF,0x31,0x00,0x00,0x00,0x00,0x00,
	//Blank 21
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x15,
	0x39, 0x00, 0x00, 0x11, 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xB0,0xC1,0xEF,
	0x39, 0x00, 0x00, 0x11, 0x90,0xE7,0x01,0x42,0xF6,0x88,0x51,0xFB,0x0B,0x22,0x23,0x2B,0x62,0xD4,0x6A,0x83,0xC8,
	0x39, 0x00, 0x00, 0x11, 0xA0,0xC8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,
	0x39, 0x00, 0x00, 0x11, 0xB0,0x33,0x62,0xD4,0x2A,0x00,0x00,0x00,0x00,0x26,0x00,0xE0,0x01,0x28,0xAD,0x09,0x9A,
	0x39, 0x00, 0x00, 0x11, 0xC0,0x92,0x95,0xA6,0x82,0xA1,0x38,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xA6,0xA0,
	0x39, 0x00, 0x00, 0x11, 0xD0,0x49,0x41,0x66,0xCA,0x20,0x04,0xD0,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0xAD,0x09,
	0x39, 0x00, 0x00, 0x11, 0xE0,0x9A,0x10,0x95,0xA6,0x00,0x81,0x30,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xA6,
	0x39, 0x00, 0x00, 0x11, 0xF0,0xA0,0x69,0x49,0x66,0xEA,0x28,0x86,0xD0,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x00,
	//Blank 22
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x16,
	0x39, 0x00, 0x00, 0x11, 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x39, 0x00, 0x00, 0x0b, 0x90,0x00,0x00,0x00,0x00,0x80,0x42,0x2B,0x01,0x00,0x00,
	//Blank 24
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x18,
	0x39, 0x00, 0x00, 0x11, 0x80,0xEF,0xBD,0xF7,0xDE,0x7B,0xEF,0xBD,0x07,0x08,0x08,0x0A,0x0C,0x0C,0x0C,0x0C,0x0C,
	0x39, 0x00, 0x00, 0x11, 0x90,0x0C,0x0C,0x0C,0x5C,0x09,0xA8,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x5A,
	0x39, 0x00, 0x00, 0x11, 0xA0,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x09,0x04,0xFF,0x00,0x80,
	0x39, 0x00, 0x00, 0x10, 0xB0,0x80,0x00,0x04,0x20,0x00,0x01,0x08,0x40,0x00,0x02,0x10,0x80,0x00,0x04,0x00,
	//Blank 25
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x19,
	0x39, 0x00, 0x00, 0x11, 0x80,0xF0,0xD9,0xC8,0xBA,0xAF,0xA6,0x9E,0x98,0x92,0x8D,0x88,0x84,0x00,0x60,0xF6,0xCF,
	0x39, 0x00, 0x00, 0x11, 0x90,0xFC,0x6F,0xF6,0xEF,0xCF,0xAF,0x0F,0xFF,0xAF,0xB5,0x71,0x0E,0x6C,0x4A,0x69,0x08,
	0x39, 0x00, 0x00, 0x05, 0xA0,0x00,0x00,0x48,0x00,
	//Blank 26
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x1A,
	0x39, 0x00, 0x00, 0x11, 0x80,0xFF,0x04,0x04,0x08,0x0C,0x00,0x10,0x14,0x18,0x1C,0x00,0x20,0x28,0x30,0x38,0x00,
	0x39, 0x00, 0x00, 0x11, 0x90,0x40,0x48,0x50,0x58,0x00,0x60,0x68,0x70,0x78,0x00,0x80,0x88,0x90,0x98,0x00,0xA0,
	0x39, 0x00, 0x00, 0x11, 0xA0,0xA8,0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,0xFC,0xFE,
	0x39, 0x00, 0x00, 0x11, 0xB0,0xFF,0x00,0x00,0x04,0x08,0x0C,0x00,0x10,0x14,0x18,0x1C,0x00,0x20,0x28,0x30,0x38,
	0x39, 0x00, 0x00, 0x11, 0xC0,0x00,0x40,0x48,0x50,0x58,0x00,0x60,0x68,0x70,0x78,0x00,0x80,0x88,0x90,0x98,0x00,
	0x39, 0x00, 0x00, 0x11, 0xD0,0xA0,0xA8,0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,0xFC,
	0x39, 0x00, 0x00, 0x11, 0xE0,0xFE,0xFF,0x00,0x00,0x04,0x08,0x0C,0x00,0x10,0x14,0x18,0x1C,0x00,0x20,0x28,0x30,
	0x39, 0x00, 0x00, 0x11, 0xF0,0x38,0x00,0x40,0x48,0x50,0x58,0x00,0x60,0x68,0x70,0x78,0x00,0x80,0x88,0x90,0x98,
	//Blank 27
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x1B,
	0x39, 0x00, 0x00, 0x11, 0x80,0x00,0xA0,0xA8,0xB0,0xB8,0x00,0xC0,0xC8,0xD0,0xD8,0x00,0xE0,0xE8,0xF0,0xF8,0x00,
	0x39, 0x00, 0x00, 0x06, 0x90,0xFC,0xFE,0xFF,0x00,0x00,
	//Blank 28
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x1C,
	0x39, 0x00, 0x00, 0x11, 0x80,0x33,0x22,0x00,0x03,0x5A,0x02,0x5A,0x54,0xE5,0xFF,0xC7,0x00,0x18,0x28,0x18,0x08,
	0x39, 0x00, 0x00, 0x11, 0x90,0x10,0x0C,0x07,0x09,0x06,0x06,0x0A,0x10,0x0C,0x09,0x0B,0x06,0x06,0xF0,0x78,0x40,
	0x39, 0x00, 0x00, 0x11, 0xA0,0x20,0x08,0x08,0x06,0x13,0xC0,0x34,0x1E,0x0A,0x08,0x66,0xD1,0xA0,0x1C,0x20,0x20,
	0x39, 0x00, 0x00, 0x11, 0xB0,0x18,0x04,0x20,0x00,0xC0,0x04,0x28,0x01,0x4C,0x00,0x23,0x18,0x10,0x0A,0x06,0xC9,
	0x39, 0x00, 0x00, 0x11, 0xC0,0x04,0x70,0x41,0x58,0x54,0xB5,0x4A,0x55,0x15,0x00,0x78,0xF8,0x99,0x99,0x99,0x99,
	0x39, 0x00, 0x00, 0x11, 0xD0,0x99,0x19,0x11,0x11,0x11,0x11,0x11,0x11,0x08,0xC8,0xE3,0x81,0x00,0x20,0x80,0x27,
	0x39, 0x00, 0x00, 0x11, 0xE0,0xE2,0x89,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x31,0x04,0x41,0xB6,0x6D,0xDB,0xB6,
	0x39, 0x00, 0x00, 0x11, 0xF0,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0xDB,0xB6,0x6D,0xC0,0x03,0x40,
	//Blank 29
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x1D,
	0x39, 0x00, 0x00, 0x11, 0x80,0x00,0x01,0x54,0x0B,0x23,0x18,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	//Blank 34
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x22,
	0x39, 0x00, 0x00, 0x10, 0x80,0x00,0x5E,0x00,0x00,0x00,0x00,0x00,0x00,0x5E,0x00,0x00,0x00,0x00,0x00,0x00,
	//Blank 36
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x24,
	0x39, 0x00, 0x00, 0x11, 0x80,0x2D,0xD3,0x00,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x1F,0x00,0xAA,0x3E,0x00,
	0x39, 0x00, 0x00, 0x05, 0x90,0x00,0x00,0x00,0x00,
	//Blank 37
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x25,
	0x39, 0x00, 0x00, 0x11, 0x80,0x01,0x05,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,
	0x39, 0x00, 0x00, 0x0c, 0x90,0x0F,0x00,0x00,0x24,0x00,0x00,0x00,0x00,0xFF,0x07,0x35,
	//Blank 38
	0x39, 0x00, 0x00, 0x03, 0x41,0x5A,0x26,
	0x39, 0x00, 0x00, 0x11, 0x80,0x00,0x83,0x00,0xFF,0xFF,0x60,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x2F,0x44,
	0x39, 0x00, 0x00, 0x04, 0x90,0x5A,0xA5,0x5A,
	//----------------------LCD initial code End----------------------//

	//SPI FINISH
	0x39, 0x00, 0x00, 0x02, 0x90,0xA5,
	//Blank select 2F
	0x39, 0x00, 0x00, 0x03, 0x41,0x00,0x2F,

	0x05, 0x78, 0x00, 0x01, 0x29,
	0x05, 0x14, 0x00, 0x01, 0x11,
	CMD_END
	//-------------  Display Initial Setting end -------------------------
};

static int mipi_dsi_send_cmds(struct sprd_dsi *dsi, void *data)
{
	uint16_t len;
	struct dsi_cmd_desc *cmds = data;

	if ((cmds == NULL) || (dsi == NULL))
		return -1;

	for (; cmds->data_type != CMD_END;) {
		len = (cmds->wc_h << 8) | cmds->wc_l;
		mipi_dsi_dcs_write(dsi, cmds->payload, len);
		if (cmds->wait)
			msleep(cmds->wait);
		cmds = (struct dsi_cmd_desc *)(cmds->payload + len);
	}
	return 0;
}

static int ft8006p_init(void)
{
	struct sprd_dsi *dsi = &dsi_device;
	struct sprd_dphy *dphy = &dphy_device;

	mipi_dsi_lp_cmd_enable(dsi, true);
	mipi_dsi_send_cmds(dsi, init_data);
	mipi_dsi_set_work_mode(dsi, SPRD_MIPI_MODE_VIDEO);
	mipi_dsi_state_reset(dsi);
	mipi_dphy_hs_clk_en(dphy, true);

	return 0;
}

static int32_t lcm_same_ic_adc_getvalue(unsigned int adc_channel)
{
	uint8_t iloop = 0, itimes = 10;
	uint32_t adc_value = 0, adc_value_all = 0;

	for (iloop=0; iloop < itimes; iloop++)
	{
		adc_value = ADC_GetValue(adc_channel, ADC_SCALE_1V2);
		adc_value_all += adc_value;
	}
	adc_value = adc_value_all / itimes;

	return adc_value;
}

static int ft8006p_readid(void)
{
	uint32_t lcd_id_vol_raw_data, id_adc;
	uint8_t adc_channel = 6;

	lcd_id_vol_raw_data = lcm_same_ic_adc_getvalue(adc_channel);
	id_adc = sprd_chan_small_adc_to_vol(adc_channel, ADC_SCALE_1V2, 0, lcd_id_vol_raw_data);
	pr_info("LCD id_adc = %dmV\n", id_adc);
	if ((id_adc > (1056 - 50)) & (id_adc < (1056 + 50)))
		return 0;
	else
		return -1;
}

static int ft8006p_power(int on)
{
	uint8_t val =0;

	if (on) {
		/*	hmct add for avdd/avee */
		i2c_set_bus_num(3);
		i2c_init(I2C_SPEED, LCD_POWER_I2C_ADDRESS);

		pr_info("FT8615 panel: set lcd power on +6.0/-6.0 ...\n");
		i2c_reg_write(LCD_POWER_I2C_ADDRESS, LCD_POWER_VPOS_ADDRESS, 0x14);
		val = i2c_reg_read(LCD_POWER_I2C_ADDRESS, LCD_POWER_VPOS_ADDRESS);
		mdelay(5);
		i2c_reg_write(LCD_POWER_I2C_ADDRESS, LCD_POWER_VNEG_ADDRESS, 0x14);
		val = i2c_reg_read(LCD_POWER_I2C_ADDRESS, LCD_POWER_VNEG_ADDRESS);

		sprd_gpio_request(NULL, CONFIG_LCM_GPIO_RSTN);
		sprd_gpio_direction_output(NULL, CONFIG_LCM_GPIO_RSTN, 0);
		sprd_gpio_request(NULL, CONFIG_CTP_GPIO_RSTN);
		sprd_gpio_direction_output(NULL, CONFIG_CTP_GPIO_RSTN, 0);

#ifdef CONFIG_LCM_GPIO_AVDDEN
		sprd_gpio_request(NULL, CONFIG_LCM_GPIO_AVDDEN);
		sprd_gpio_direction_output(NULL, CONFIG_LCM_GPIO_AVDDEN, 1);
		mdelay(3);
#endif
#ifdef CONFIG_LCM_GPIO_AVEEEN
		sprd_gpio_request(NULL, CONFIG_LCM_GPIO_AVEEEN);
		sprd_gpio_direction_output(NULL, CONFIG_LCM_GPIO_AVEEEN, 1);
		mdelay(3);
#endif
		sprd_gpio_direction_output(NULL, CONFIG_CTP_GPIO_RSTN, 1);
		sprd_gpio_direction_output(NULL, CONFIG_LCM_GPIO_RSTN, 1);
		mdelay(60);
	} else {
		sprd_gpio_direction_output(NULL, CONFIG_LCM_GPIO_RSTN, 0);
		mdelay(5);
	}

	return 0;
}

static int ft8006p_set_brightness(int level)
{
	uint8_t temp=0;
	uint8_t val =0;

	temp &= ~0x07;
	temp |= level & 0x07;

	sprd_gpio_request(NULL, CONFIG_LCM_GPIO_BL_EN);
	sprd_gpio_direction_output(NULL, CONFIG_LCM_GPIO_BL_EN, 1);
	mdelay(40);

	i2c_set_bus_num(3);
	i2c_init(I2C_SPEED, BL_POWER_I2C_ADDRESS);

	temp &= ~0x07;
	temp |= level & 0x07;
	i2c_reg_write(BL_POWER_I2C_ADDRESS, BL_CURRENT_RATIO_LSB_ADDRESS, 0x07);
	val = i2c_reg_read(BL_POWER_I2C_ADDRESS, BL_CURRENT_RATIO_LSB_ADDRESS);
	temp=0;
	temp &= ~0xff;
	temp |= level & 0xff;
	i2c_reg_write(BL_POWER_I2C_ADDRESS, BL_CURRENT_RATIO_MSB_ADDRESS, 0xff);
	val = i2c_reg_read(BL_POWER_I2C_ADDRESS, BL_CURRENT_RATIO_MSB_ADDRESS);
	i2c_reg_write(BL_POWER_I2C_ADDRESS, BL_POWER_PWM_ADDRESS, 0x5B);
	if (level > 0) {
		i2c_reg_write(BL_POWER_I2C_ADDRESS, BL_POWER_MODE_ADDRESS, 0x99);//open backlight
		pr_info( "LCD backlight KTD3133 on  ... brightness = %d\n", level);
	} else {
		i2c_reg_write(BL_POWER_I2C_ADDRESS, BL_POWER_MODE_ADDRESS, 0x98);//close backlight
		pr_info( "LCD backlight KTD3133 closed  ...\n");
	}
};

static struct panel_ops ft8006p_ops = {
	.init = ft8006p_init,
	.read_id = ft8006p_readid,
	.power = ft8006p_power,
	.set_brightness= ft8006p_set_brightness
};

static struct panel_info ft8006p_info = {
	/* common parameters */
	.lcd_name = "lcd_ft8006p_hlt_mipi_hdp",
	.type = SPRD_PANEL_TYPE_MIPI,
	.bpp = 24,
//	.fps = 60,
	.width = 720,
	.height = 1600,

	/* DPI specific parameters */
	.pixel_clk = 96000000, /*Hz*/
	.rgb_timing = {
		.hfp = 72,
		.hbp = 72,
		.hsync = 16,
		.vfp = 132,
		.vbp = 108,
		.vsync = 4,
	},

	/* MIPI DSI specific parameters */
	.phy_freq = 680000,
	.lane_num = 4,
	.work_mode = SPRD_MIPI_MODE_VIDEO,
	.burst_mode = VIDEO_BURST_WITH_SYNC_PULSES,
	.nc_clk_en = false,
};

struct panel_driver ft8006p_hlt_driver = {
	.info = &ft8006p_info,
	.ops = &ft8006p_ops,
};
